package org.samith.web.servlet;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.UserTransaction;

import org.samith.entity.Transaction;

@SuppressWarnings("serial")
public class PaymentGatewayServlet extends HttpServlet {
	
	@Resource
	UserTransaction tx;
	
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		ServletContext context = getServletConfig().getServletContext();
		context.getRequestDispatcher("/Payments/index.jsp").forward(request, response);
	}
	
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			tx.begin();
				Transaction trn = new Transaction();
				trn.setAmount(Double.parseDouble(request.getParameter("amount")));
				System.out.println(" =========== Trnasaction committed =================== ");
			tx.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
